import { getDictionaryBackgroundColor, getDictionaryLabel } from "@/utils";
import { Tag } from "antd";
import { useState, useEffect, FC } from "react";

interface DictionaryColumnRenderProps {
    dictType: string;
    value: number | boolean | string;
}
const DictionaryColumnRender: FC<DictionaryColumnRenderProps> = ({ dictType, value }) => {
    const [label, setLabel] = useState("");
    const [backgroundColor, setBackgroundColor] = useState("");

    useEffect(() => {
        getDictionaryLabel(dictType, value).then(res => setLabel(res));
        getDictionaryBackgroundColor(dictType, value).then(res => setBackgroundColor(res));
    }, [value, dictType]);

    if (!backgroundColor) return label;
    return <Tag color={backgroundColor}>{label}</Tag>;
};

export default DictionaryColumnRender;
